//
//  UtiliTools.m
//  SIqICalendar
//
//  Created by SKiran on 17/2/27.
//  Copyright © 2017年 sjw. All rights reserved.
//

#import "UtiliTools.h"

@implementation UtiliTools

static UtiliTools *_utiliTools;
+ (UtiliTools *)utilShareIntance {
    if (_utiliTools == nil) {
        _utiliTools = [[UtiliTools alloc]init];
    }
    return _utiliTools;
}

/**
 *  uicolor转换nsstring
 *
 *  @param color 要转换的UIColor
 *
 *  @return 转换完毕的NSString
 */
- (NSString *)colorToNSString:(UIColor *)color {
    @try {
        CGColorRef colorRef = color.CGColor;
        NSString *colorString = [CIColor colorWithCGColor:colorRef].stringRepresentation;
        return colorString;
    }
    @catch (NSException *exception) {
        return @"0 0 0 0";
    }
    
    
}

/**
 *  NSString 转 UIColor
 *
 *  @param colorStr 要转换的NSString
 *
 *  @return 转换完毕的UIColor
 */
- (UIColor *)strToColor:(NSString *)colorStr {
    NSArray * colorParts = [colorStr componentsSeparatedByString: @" "];
    
    CGFloat red = [[colorParts objectAtIndex:0] floatValue];
    CGFloat green = [[colorParts objectAtIndex:1] floatValue];
    CGFloat blue = [[colorParts objectAtIndex:2] floatValue];
    CGFloat alpha = [[colorParts objectAtIndex:3] floatValue];
    
    UIColor * newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
    
    return newColor;
//    @try {
//        CIColor *cicolor = [CIColor colorWithString:colorStr];
//        UIColor *color = [UIColor colorWithCIColor:cicolor];
//        return color;
//    }
//    @catch (NSException *exception) {
//        return [UIColor blackColor];
//    }
}

- (void)saveDataByNSUserDefaultsWithValue:(id)value {
    NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.sjw.siqicalendar"];
    [shared setObject:value forKey:@"widget"];
    [shared synchronize];
}

- (void)saveChangedTurnDataByNSUserDefaultsWithValue:(id)value  {
    NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.sjw.siqicalendar"];
    [shared setObject:value forKey:@"widget_changed"];
    [shared synchronize];
}
@end
